package com.decent.web.system.dao;

import com.decent.common.entity.common.Order;
import com.decent.web.system.dao.provider.SystemOrderDaoProvider;
import com.decent.web.system.dto.PayOrderDTO;
import com.decent.web.system.dto.SystemOrderDTO;
import com.decent.web.system.vo.SystemOrderVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: decent Gjh
 * @date: 2022/10/29/16:50
 * @description:
 */
@Mapper
public interface SystemOrderDao {

    /**
     * 创建订单
     * @param orderDTO  订单信息
     * @return 影响行数
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into common_order (user_id, good_id, goods_name, brand_id, classify_id, order_state, order_uuid, num, total_price, create_datetime) " +
            "values (#{order.userId}, #{order.goodId}, #{order.goodsName}, #{order.brandId}, #{order.classifyId}," +
            " #{order.orderState}, #{order.orderUuid}, #{order.num}, #{order.totalPrice}, now() ) ")
    int installOrder(@Param("order") Order orderDTO);

    /**
     * 查找对应uuid的订单
     * @param createOrderDTO 订单uuid
     * @return 订单详细信息
     */
    @Select("select * from common_order where order_uuid = #{order.orderUuid} ")
    SystemOrderDTO selectByUuid(@Param("order") PayOrderDTO createOrderDTO);

    /**
     * 更新订单状态
     * @param dto 订单信息
     */
    @Update("update common_order set order_state = #{order.orderState} ," +
            " cheng_order_no = #{order.chengOrderNo} , update_datetime = now() " +
            "where id = #{order.id} ")
    void updateOrder(@Param("order") SystemOrderDTO dto);

    /**
     * 根据条件查找订单
     * @param order 查询条件
     * @return 订单列表
     */
    @SelectProvider(type = SystemOrderDaoProvider.class, method = "list")
    List<SystemOrderVO> selectOrderList(@Param("order") SystemOrderDTO order);

}
